 /*
 * @description: 临期商品
 * @Author: along
 * @Date: 2021-06-15
 * @Last Modified by: along
 * @Last Modified time: 2021-06-15
 */
<template>
    <div
        class="nearExpActive"
        @click="emitEvent(8)"
        v-if="isLoad"
    >
        <div
            class="__wrap"
            :style="{
                background: 'rgba(255, 253, 252, 1)',
                borderRadius: '8px'
            }"
        >
            <div class="__header">
                <img
                    src="https://cdn.zsdx.cn/student-app/images/active-home/nexp_bg.png"
                    class="__header_bg"
                >
                <div class="__header_wrap">
                    <div class="__left">
                        <p class="__title">倒计食</p>
                        <p class="__desc">每日更新</p>
                    </div>
                    <div class="__right">
                        <p class="__next">查看更多</p>
                        <i class="iconfont el-icon-hand-zuojiantou1"/>
                    </div>
                </div>
            </div>
            <div class="__box">
                <el-carousel
                    height="175px"
                    class="__carousel"
                    :interval="115000"
                >
                    <el-carousel-item
                        v-for="(row,index) in dataList"
                        :key="index"
                        class="__carousel_item"
                        :style="{height: '175px'}"
                    >
                        <div class="__items_wrap">
                            <div
                                v-for="(el,key) in row"
                                :key="key"
                                class="__items"
                            >
                                <img
                                    :src="el.goods_cover"
                                    class="__items_cover"
                                >
                                <div class="__items_title">
                                    {{ el.goods_title }}
                                </div>
                                <div class="__items_price">
                                    <p class="__items_icon">¥</p>
                                    <p class="__items_goods_price">{{ el.goods_price }}</p>
                                </div>
                                <div class="__items_foot">
                                    <img
                                        v-if="!!el.goods_discount_vip"
                                        class="__items_logo"
                                        src="https://cdn.zsdx.cn/student-app/images/active-home/nexp_bg.png"
                                    >
                                    <p class="__items_origin">
                                        ¥{{ el.goods_price_origin }}
                                    </p>
                                </div>
                            </div>
                        </div>
                    </el-carousel-item>
                </el-carousel>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'NearExpActive',
    props: {
        // baseconfig: {
        //     type: Object,
        //     default: () => {}
        // },
        index: {//存在多个相同组件,查询当前位置
            type: Number,
            default: () => {}
        }
    },
    data () {
        return {
            // rate: '0px 0px 0px 0px',
            isLoad: false,
            "goods_activity_near_exp": {
                "goods_list": []
            },
            dataList: []
        };
    },
    watch: {
        //圆角单位转换
        // baseconfig:  {
        //     handler: function (val, oldVal) {
        //         let rateValue = val.style.borderRadius;

        //         this.rate = rateValue.replace(/rpx/g, 'px');
        //         this.isLoad = true;
        //     },
        //     deep: true
        // }
    },
    mounted () {
        this.isLoad = true;
        // if(JSON.stringify(this.baseconfig.style) !== '{}') {//回填圆角
        //     let rateValue = this.baseconfig.style.borderRadius;

        //     this.rate = rateValue.replace(/rpx/g, 'px');
        // }

        this.$post('/student/custom_page_for_shop_index%5Cget_data_for_app_show', {
            item_type: 8,
            data_json: JSON.stringify({})
        }, resp => {
            if(resp.code == 1){
                this.$set(this.goods_activity_near_exp, 'goods_list', resp.data.data.goods_list);
                this.initData();
            }
        });

    },
    methods: {
        /**
         * @description 点击组件，向上级传递点击类型
         */
        emitEvent (type) {
            this.$emit('emit', {
                type: type,//组件类型
                index: this.index//组件位置
            });
        },

        initData () {
            this.dataList = [];
            const goods_list = this.goods_activity_near_exp.goods_list;

            for(let i=0; i<goods_list.length; i+= 3) {
                this.dataList.push(goods_list.slice(i, i + 3));
            }

            // console.log('dataList', this.dataList);
        }
    }
};
</script>

<style lang="less" scoped>
.nearExpActive {
    width: 375px;
    box-sizing: border-box;
    border: 1px #ffffff solid;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(242, 242, 242, 1);
    .__wrap {
        width: 355px;
        height: 233px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
        .__header {
            width: 355px;
            height: 60px;
            position: relative;
            .__header_bg {
                width: 355px;
                height: 60px;
                position: absolute;
                left: 0;
                top: 0;
                z-index: 0;
            }
            .__header_wrap {
                width: 355px;
                height: 16px;
                position: absolute;
                left: 0;
                top: 15px;
                z-index: 10;
                box-sizing: border-box;
                padding: 0 10px;
                display: flex;
                justify-content: space-between;
                .__left {
                    height: 16px;
                    display: flex;
                    .__title {
                        font-size: 16px;
                        color: rgba(255, 255, 255, 1);
                        font-weight: bold;
                        height: 16px;
                        line-height: 16px;
                        margin-right: 8px;
                    }
                    .__desc {
                        color: rgba(255, 255, 255, 1);
                        font-size: 12px;
                        height: 12px;
                        line-height: 12px;
                        margin-top: 4px;
                    }
                }
                .__right {
                    display: flex;
                    align-items: center;
                    .__next {
                        color: rgba(255, 255, 255, 1);
                        font-size: 12px;
                    }
                    .el-icon-hand-zuojiantou1 {
                       font-size: 14px;
                       font-weight: 500;
                       color: #ffffff;
                       transform: rotate(180deg);
                       position: relative;
                       top: -1px;
                    }
                }
            }
        }
        .__box {
            width: 345px;
            height: 175px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            overflow: hidden;
            box-sizing: border-box;
            margin-top: -9px;
            .__items_wrap {
                width: 345px;
                display: flex;
                align-items: center;
                justify-content: space-between;
                .__items {
                    width: 111px;
                    height: 175px;
                    border-radius: 4px 4px 0 0;
                    box-sizing: border-box;
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    .__items_cover {
                        width: 111px;
                        height: 111px;
                        border-radius: 4px 4px 0 0;
                    }
                    .__items_title {
                        width: 105px;
                        height: 16px;
                        color: rgba(51, 51, 51, 1);
                        font-size: 14px;
                        line-height: 16px;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                        margin: 7px 0 6px 0;
                        overflow: hidden;
                    }
                    .__items_price {
                        width: 105px;
                        height: 16px;
                        display: flex;
                        margin: 3px 0 6px 0;
                        .__items_icon {
                            color: rgba(252, 38, 38, 1);
                            font-size: 10px;
                            font-weight: 500;
                            height: 10px;
                            line-height: 10px;
                            margin-top: 4px;
                        }
                        .__items_goods_price {
                            color: rgba(252, 38, 38, 1);
                            font-size: 16px;
                            height: 16px;
                            line-height: 16px;
                            font-weight: bold;
                        }
                    }
                    .__items_foot {
                        width: 105px;
                        display: flex;
                        align-items: center;
                        .__items_logo {
                            width: 30px;
                            height: 12px;
                            margin-right: 4px;
                        }
                        .__items_origin {
                            color: rgba(153, 153, 153, 1);
                            font-size: 12px;
                            font-weight: 500;
                            text-decoration: line-through;
                        }
                    }
                }
            }
        }
    }
}
</style>
<style lang="less" scoped>
.nearExpActive {
    .__carousel {
        width: 345px;
        height: 175px;
        overflow: hidden;
        .__carousel_item {
            width: 345px;
            height: 175px;
        }
    }
}
</style>